var pageCount = 0;
function classOnload(a){
    console.log(a);
// }


var Json ={
    pageIndex:a,
    pageSize:9

}
ajax.post(ajax.myUrl+"project/findProjectList",Json,function(result){
    console.log(result);
    response(result);
    var data = result.dataset.projectList;
    // console.log(data)
    var tbody = document.querySelector("tbody");
    tbody.innerHTML = ""
    for(var i=0;i<data.length;i++){
        var newtr = document.createElement("tr");
        newtr.innerHTML=`
        <td>${i+1}</td>
            <td>${data[i].projectName}</td>
            <td>${data[i].projectLeader}</td>
            <td>${data[i].workingHours}</td>
            <td>${data[i].startDate}</td>
            <td>${data[i].endDate}</td>
            <td>${data[i].progress+"%"}</td>
            
            <td><div class="more">详情</div></td>
         
         `;
         tbody.appendChild(newtr);
    }
    //当点击详情的时候跳转到项目详情页
    var more = document.querySelectorAll(".more");
    // console.log(more);
    for(var j=0;j<more.length;j++){
        more[j].onclick=function(){
            localStorage.setItem("projectId","");
            for(var k=0;k<more.length;k++){
                if(this==more[k]){
                    console.log(data[k].projectId)
                    localStorage.setItem("projectId",data[k].projectId);
                    location.href="Project-Details.html";
                }
            }
        }
    }
})

}
// 鼠标经过加号显示要添加的内容
var addition = document.getElementsByClassName("addition")[0];
var img = addition.getElementsByTagName("img")[0];
var add = addition.getElementsByClassName("add")[0];
img.onmouseover = function(){
    add.style.display = "block";
}
img.onmouseleave = function(){
    add.style.display = "none";
}
//点击添加项目 模态框显示
img.onclick = function(){
   var mask = document.querySelector("#mask");
   var addProject = document.querySelector("#addProject");
   mask.setAttribute("class","maskShow");
   addProject.setAttribute("class","projectShow");
   ajax.post(ajax.myUrl+"project/findFreeUser",null,function(result){
    console.log(result)
    var data1=result.dataset;
    var select = document.getElementById("people");
    var arrFreeUser=[];
    var arrFreeId=[];
    for(var i=0;i<data1.length;i++){
        select.add(new Option(data1[i].userName,data1[i].userId))
        arrFreeUser[i]=data1[i].userName;
        arrFreeId[i]=data1[i].userId;
    }
    // console.log(arrFreeUser)
    localStorage.setItem("freeUser",arrFreeUser)
    localStorage.setItem("freeId",arrFreeId)
   })
}
//添加项目完成时，点击确定或取消 撤销模态框和蒙版
var Pcontent2 = document.querySelector(".Pcontent2");
var btn1 = Pcontent2.querySelectorAll("button")[0];
btn1.onclick = function(){
    var mask = document.querySelector("#mask");
   var addProject = document.querySelector("#addProject");
   mask.setAttribute("class","maskShowNone");
   addProject.setAttribute("class","projectShowNone");
   var inputs2 = document.querySelectorAll("input");
//    console.log(inputs2)
    //获取所有空闲人员
    
    var select = document.getElementById("people");
   var Json2={
    startDate:inputs2[5].value,
    endDate:inputs2[6].value,
    projectName:inputs2[3].value,
    projectLeader:select.value,
    workingHours:Number(inputs2[4].value)
   }
//    console.log(Json2)
   ajax.post(ajax.myUrl+"project/addProject",Json2,function(result){

   })
}
var btn2 = Pcontent2.querySelectorAll("button")[1];
btn2.onclick = function(){
    var mask = document.querySelector("#mask");
   var addProject = document.querySelector("#addProject");
   mask.setAttribute("class","maskShowNone");
   addProject.setAttribute("class","projectShowNone");
}
var search = document.querySelector("button")
search.onclick=function(){
    var inputs3 = document.querySelectorAll("input");
    console.log(inputs3)
    var starTime = inputs3[1].value;
    if(starTime==""){
        starTime=null
    }else{
        starTime=inputs3[1].value
    }
    var endTime = inputs3[2].value;
    if(endTime==""){
        endTime=null;
    }else{
        endTime=inputs3[2].value
    }
    var Json3={
        projectName:inputs3[0].value,
        pageIndex:1,
        pageSize:5,
        time1:starTime,
        time2:endTime

    }
    console.log(Json3)
    ajax.post(ajax.myUrl+"project/findProjectList",Json3,function(result){
    console.log(result)
    var data = result.dataset.projectList;
    var tbody = document.querySelector("tbody");
    tbody.innerHTML=``
    for(var i=0;i<data.length;i++){
        var newtr = document.createElement("tr");
        newtr.innerHTML=`
        <td>${data[i].projectId}</td>
            <td>${data[i].projectName}</td>
            <td>${data[i].projectLeader}</td>
            <td>${data[i].workingHours}</td>
            <td>${data[i].startDate}</td>
            <td>${data[i].endDate}</td>
            <td>${data[i].progress*100+"%"}</td>
            
            <td><div class="more">详情</div></td>
         
         `;
         tbody.appendChild(newtr);
    }
   })
}


